home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ahoy 1985 December
/
Ahoy_Magazine_85-12_1985_Double_L.d64
/
dir manipulator
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-10-26
|
6KB
|
171 lines
10 rem ******************************
20 rem * directory manipulator init *
30 rem ******************************
40 print"[147]"tab(9)"[144]directory manipulator[159]"
50 printtab(5)"insert diskette to manipulate":gosub1430
60 dimf$(144):fori=1to11:fl$=fl$+chr$(0):next:ty$=chr$(131)+chr$(18)+chr$(0)
70 dims%(18):s%(1)=1:fori=1to17
80 ifi=6thens%(i+1)=2:next
90 ifi=12thens%(i+1)=3:next
100 s%(i+1)=s%(i)+3:next
110 t=18:s=1:n=1:ok=0
120 sp$="":fori=1to16:sp$=sp$+chr$(160):next
130 rem ******************
140 rem * init disk unit *
150 rem ******************
160 open15,8,15,"i0":gosub1550
170 printtab(12)" disk unit ok !"
180 rem **************************
190 rem * read directory routine *
200 rem **************************
210 open2,8,2,"#"
220 print#15,"u1";2;0;t;s
230 gosub1550
240 get#2,t$,s$:rem * track & sector of next dir entry *
250 t=asc(t$+chr$(0)):s=asc(s$+chr$(0))
260 fori=1to8
270 f$="":forx=1to30:rem * get directory entries *
280 get#2,b$:b=asc(b$+chr$(0)):ifx=1thena=b
290 ifx=4thenc=b
300 f$=f$+chr$(b):nextx
310 ifa<>0or(a=0andc=160)thenf$(n)=f$:n=n+1
320 get#2,b$,b$:nexti:rem * dir entries 2-7 garbage 1st 2 bytes *
330 ift<>0then220
340 rem ***************************
350 rem * print directory routine *
360 rem ***************************
370 z=1:od=0:p1=20:pg=p1:x=int((n-1)/2)+1:if(n-1)-(2*(x-1))=1thenx=x+1:od=1
380 xx=x-1:pc=int(xx/pg):if(xx/pg)-pc<>0thenpc=pc+1
390 ifxx>pgthenx=pg+1
400 fori=1toxx:print"[144]"right$(str$(z),2)"[159]";mid$(f$(z),4,16):z=z+1
410 ifod=0or(od=1and2*xx<>x)thenprinttab(19)"[145][144]"right$(str$(x),2)"[159]";mid$(f$(x),4,16):x=x+1
420 ifint(i/pg)=1andpc>=2thenpg=pg+p1:gosub1430:pc=pc-1:goto440
430 goto460
440 z=x:ifpc=>2thenx=z+p1
450 ifpc=1thenx=int(((2*xx)-(2*i))/2)+z
460 nexti
470 close15:close2
480 rem *****************
490 rem * check dir ok? *
500 rem *****************
510 print:print"directory ok (y/n)";:input"n[157][157][157]";ok$
520 ifok$<>"y"andok$<>"n"thenprint"[145][145][145]":goto510
530 ifok$="y"andok=0thengoto1660:rem * exit dir manipulator *
540 ifok$="y"andok=1thengoto730:rem * re-write directory *
550 rem ********************
560 rem * select manip cmd *
570 rem ********************
580 print"select directory manipulation command:"
590 getcm$:ifcm$=""then590
600 ifcm$="[133]"thenprint"re-list directory":goto370
610 ifcm$="h"thengosub1340:goto370
620 ok=1:ifcm$="[137]"thenprint"alphabatize directory":gosub920:goto370
630 ifcm$="[134]"thenprint"insert blank entry":gosub1010:goto370
640 ifcm$="[138]"thenprint"delete blank entries":gosub1050:goto370
650 ifcm$="[135]"thenprint"insert -----[146] entry":gosub1130:goto370
660 ifcm$="[139]"thenprint"insert 'remark' entry":gosub1170:goto370
670 ifcm$="[136]"thenprint"swap directory entries":gosub1230:goto370
680 ifcm$="[140]"thenprint"delete directory entry":gosub1280:goto370
690 print"[147]":goto580
700 rem **********************
710 rem * re-write directory *
720 rem **********************
730 print"[147] writing new directory...please wait![146]"
740 f$="":fori=1to32:f$=f$+chr$(0):nexti
750 open15,8,15,"i0":gosub1550
760 printtab(12)" disk unit ok !"
770 open2,8,2,"#":x=int((n-1)/8):xx=0:if((n-1)/8)-x<>0thenx=x+1
780 fori=1tox:print#15,"b-p:";2;0:rem * position buffer pointer *
790 t=18:ifi=xthent=0:rem * set next dir sec pointer to 0 if last sector *
800 print#2,chr$(t);chr$(s%(i+1));:rem * pointer to next tr/se of dir *
810 forz=1to8:xx=xx+1
820 ifxx=>nthenprint#2,f$;:goto850
830 print#2,f$(xx);:rem * put dir entries into buffer *
840 ifz<>8andxx<>(n-1)thenprint#2,"sg";:rem * trash bytes for dir entries 2-7 *
850 nextz
860 print#15,"u2:";2;0;18;s%(i):rem * write dir sector *
870 print"writing track 18 sector"str$(s%(i))
880 nexti:close2:close15:goto1660
890 rem *************************
900 rem * alphabatize directory *
910 rem *************************
920 x=n
930 x=int(x/2):ifx=0thenreturn
940 fori=1to((n-1)-x):y=i
950 z=y+x:ifmid$(f$(y),4,16)<=mid$(f$(z),4,16)then970
960 ff$=f$(y):f$(y)=f$(z):f$(z)=ff$:y=y-x:ify>0then950
970 next:goto930
980 rem **********************
990 rem * insert blank entry *
1000 rem **********************
1010 gosub1490:f$(bl)=chr$(0)+chr$(0)+chr$(0)+sp$+fl$:return
1020 rem ************************
1030 rem * delete blank entries *
1040 rem ************************
1050 fori=1ton-1:ifasc(f$(i))=0then1070
1060 next:return
1070 forx=blton-1
1080 ifbl<n-1thenf$(x)=f$(x+1)
1090 next:n=n-1:goto1050
1100 rem **********************
1110 rem * insert ----- entry *
1120 rem **********************
1130 gosub1490:f$(bl)=ty$+"----------------"+fl$:return
1140 rem *************************
1150 rem * insert 'remark' entry *
1160 rem *************************
1170 gosub1490:print"enter remark:";:inputrm$:iflen(rm$)>16then1170
1180 iflen(rm$)<16thenfori=1to(16-len(rm$)):rm$=rm$+chr$(160):next
1190 f$(bl)=ty$+rm$+fl$:return
1200 rem *************************
1210 rem * swap directory entries *
1220 rem *************************
1230 print"1st ";:gosub1490:a=bl:print"2nd ";:gosub1490:f$(b)=f$(a):f$(a)=f$(bl)
1240 f$(bl)=f$(b):return
1250 rem **************************
1260 rem * delete directory entry *
1270 rem **************************
1280 gosub1490:forx=blton-1
1290 ifbl<n-1thenf$(x)=f$(x+1)
1300 next:n=n-1:return
1310 rem *************
1320 rem * help menu *
1330 rem *************
1340 print"[147] directory manipulator help menu"
1350 print" f1 -> re-list directory":print" f2 -> alphabatize directory"
1360 print" f3 -> insert blank entry":print" f4 -> delete blank entries"
1370 print" f5 -> insert -----[146] entry":print" f6 -> insert 'remark' entry"
1380 print" f7 -> swap directory entries":print" f8 -> delete directory entry"
1390 gosub1430:return
1400 rem **********************
1410 rem * hit key subroutine *
1420 rem **********************
1430 print:printtab(13)"hit any key!!!"
1440 getck$:ifck$=""then1440
1450 return
1460 rem **************************************************
1470 rem * loc of entry/move dir array entries subroutine *
1480 rem **************************************************
1490 print"location of entry: [157][157][157][157]";:inputbl:ifbl>n-1orbl<1thenprint"[145][145]":goto1490
1500 ifcm$="[136]"orcm$="[140]"thenreturn
1510 n=n+1:fori=n-1tobl+1step-1:f$(i)=f$(i-1):next:return
1520 rem *********************
1530 rem * disk status check *
1540 rem *********************
1550 input#15,en,em$,et,es:ifen<>0thengoto1600
1560 return
1570 rem ***************************
1580 rem * disk unit error routine *
1590 rem ***************************
1600 print"[147]"tab(12)"disk unit error!"
1610 print"error # -"en"[157]; track -"et"[157]; sector -"se
1620 print"error msg - "em$:end
1630 rem ******************************
1640 rem * exit directory manipulator *
1650 rem ******************************
1660 print"[147]manipulate another diskette (y/n)";:input"n[157][157][157]";an$
1670 ifan$<>"y"andan$<>"n"then1660
1680 print"diskette being validated":open15,8,15:print#15,"v":print#15,"i":close15
1690 ifan$="y"thenrun
1700 end